package org.nokatag.code;

import java.util.Random;

public class RandomWordFactory
implements WordFactory
{

protected String characters;
protected int minLength;
protected int maxLength;

public void setCharacters(String characters)
{
    this.characters = characters;
}

public void setMinLength(int minLength)
{
    this.minLength = minLength;
}

public void setMaxLength(int maxLength)
{
    this.maxLength = maxLength;
}

public RandomWordFactory()
{
    characters = "absdeghjkmnpqrstuwxyzABCDEFGHIJKLMNPQRST23456789";
    minLength = 3;
    maxLength = 3;
}

public String getNextWord()
{
    Random rnd = new Random();
    StringBuffer sb = new StringBuffer();
    int l = minLength + (maxLength <= minLength ? 0 : rnd.nextInt(maxLength - minLength));
    for(int i = 0; i < l; i++)
    {
        int j = rnd.nextInt(characters.length());
        sb.append(characters.charAt(j));
    }

    return sb.toString();
}
}
